package com.webxiaohua.algorithm;

/**
 * @author shenxinhua
 * @date 2019-06-30 14:29
 * @desc 字符串顺时针输出为正方形
 */
public class Lesson1 {

    public static void doIt(String sourceStr){
        char[] chars = sourceStr.toCharArray();
        int k = chars.length/4; // 每行显示的字符个数
        char[] spaces = new char[k-1]; //
        for(int i=0;i<k-1;i++){
            spaces[i] = ' ';
        }
        String spaceStr = new String(spaces);
        for(int i=0;i<k+1;i++){ // 控制行数
            if(i == 0){
                System.out.println(sourceStr.substring(0,k+1));
            }else if(i >0 && i < k){
                System.out.println(chars[4*k-i]+spaceStr+chars[k+i]);
            }else{
                System.out.println(new StringBuilder(sourceStr.substring(2*k,3*k+1)).reverse().toString());
            }
        }
    }

    public static void main(String... args){
        doIt("abcdefghijkl");
    }
}
